// 首页的设置
AppHome = Ext.extend(Ext.Panel, {
	constructor : function(_cfg) {
		Ext.applyIf(this, _cfg);
		this.initUIComponents();
		AppHome.superclass.constructor.call(this, {
					title : '个人桌面',
					closable : false,
					id : 'AppHome',
					border : false,
					iconCls : 'menu-desktop',
					layout : 'border',
					defaults:{
					    padding:'0 5 0 0'
					},
					items : [this.portalPanel, this.chartPanel]
				});
	},
	initUIComponents : function() {
		this.chartPanel = new Ext.panel.Panel({
			region : 'south',
			height: 240,
			border: 0,
			layout : 'anchor',
			anchor : '100% 100%',
			style : 'display:block;',
			items: [{html:'', border:false}]
		});	
		Ext.defer(function() {
				this.showChartPanel();
			}, 200, this);
		
		this.portalPanel = Ext.create('Ext.ux.portlet.PortalPanel', {
			xtype : 'portalpanel',
			border : false,
			region : 'center',
			layout: 'column',
			items : [{
					xtype : 'portalcolumn',
					columnWidth : 0.5,
					defaults: {
						margin : '10 10 10 10'
					},
	                items:[{
						name : 'news',
						id : 'AppHome_tongbao',
						title : '通知通报',
						iconCls : 'menu-diary',
						closable : false,
						loader : {
							autoLoad : true,
							url : __ctxPath + '/comm/desktopTongBao.do?limit=8'
						},
						tools : [{
							type : 'refresh',
							tooltip : '刷新',
							scope : this,
							handler : function() {
								this.portalPanel.getCmpByName('news').loader.load();
							}
						}]
					}]
	            },{
	            	xtype : 'portalcolumn',
	            	columnWidth : 0.5,
	            	defaults: {
						margin : '10 10 10 10'
					},
	                items:[{
	                		name: 'todoTask',
	                		title : '待办事项',
							iconCls:'menu-flowWait',
							closable: false, 
							loader: {
								autoLoad: true,
								url:__ctxPath+ '/byxt/todoListMyWork.do',
								scripts:true
							},
							tools: [{
								type:'refresh',
    							tooltip: '刷新',
    							scope: this,
								handler : function() {
									this.portalPanel.getCmpByName('todoTask').loader.load();
								}
							}]
	                	}, {
	                		name: 'message',
	                		title : '未读消息',
							iconCls:'menu-message',
							closable: false, 
							loader: {
								autoLoad: true,
								url:__ctxPath+ '/info/displayInMessage.do'
							},
							tools: [{
								type:'refresh',
    							tooltip: '刷新',
    							scope: this,
								handler : function() {
									this.portalPanel.getCmpByName('message').loader.load();
								}
							}]
	                	}]
	            }]
		});
	},
	
	// 显示所有图
	showChartPanel : function(params) {
		params = params || {};
		var me = this;
		$postAjax({
			async : true,
			url : __ctxPath + "/byxt/showChartStats.do",
			params : params,
			callback : function(data) {
				for(var i=0; i<data.length; i++) {
					var option = {
						title : {
							text : data[i].title,
							x : 'center',
							textStyle : {
								fontWeight : 'bold'
							}
						},
						tooltip : {
							trigger : 'item',
							formatter : "{b} : <br/>{c} ({d}%)"
						},
						series : [{
					            type:'pie',
					            radius : '55%',
					            center: ['50%', '66%'],
					            data: data[i].data
					        }]
					};
					me.chartPanel.items.add(new Ext.ux.EChartsComponent({
						id : 'chartPanel_grade_' + data[i].id,
						anchor : '25% 70%',
						style : 'display:block;float:left;',
						height : 100,
						option: option
					}));
				}			
				me.chartPanel.doLayout();
			}
		});
	}

});
